package com.houor.device.controller;

import com.houor.device.controller.handler.codec.ControllerFrameDecoder;
import com.houor.device.controller.handler.codec.ControllerFrameEncoder;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

public class DataClientInitializer extends ChannelInitializer<SocketChannel> {
	@Override
	public void initChannel(SocketChannel ch) {
		ChannelPipeline pipeline = ch.pipeline();

		// Add the number codec first,
		pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(2000, 0, 2, 0, 2));
		pipeline.addLast(new ControllerFrameDecoder());
		pipeline.addLast(new ControllerFrameEncoder());

		// and then business logic.
		pipeline.addLast(new DataClientHandler());
	}

}
